<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}

.cellclass {
	font-color: #000000;
	background-color: #FFEBE6;
	color: red;
}

.deepDark {
	background-color: #CCC488;
}

.normalDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.pieTable {
	width: 1200px;
	border-spacing: 10px;
}

.pieTable td {
	width: 100%;
	background-color: #f0f0f0;
	text-align: center;
}
.summaryStyle {
	color: red;
	text-align: right;
	font-weight: bolder;
}
</style>
<script>
	var stateData = [ {
		id : "1",
		text : "待返费"
	}, {
		id : "2",
		text : "已返费"
	} ];
</script>

</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td><a class="mini-button" id="rebackBtn" plain="true"
					iconCls="icon-list" onclick="status1">返回列表</a>
					<div id="typeBtn" class="mini-radiobuttonlist" repeatItems="1"
						repeatLayout="table" repeatDirection="vertical"
						style="float: left; margin-top: 4px;" textField="text"
						valueField="id" value="1" onvaluechanged="changeState"
						data="stateData"></div> <a width="100px"></a> &nbsp;&nbsp;<span
					id="separatorId2" class="separator"> <a class="mini-button"
						id="checkBtn" iconCls="icon-check" plain="true" onclick="checkBatch">返费</a>
				</span></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px;">
				<div id="datagrid1" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="20"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagridDrawCell" onrowdblclick="gridRowDbClick"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail"
					ondrawsummarycell="onDrawSummaryCell" showSummaryRow="true"
					showFilterRow="false" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div type="checkcolumn" width="40px" align="center"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch()">清除
							</a>
						</div>
						<div field="CardID" width="200px" headerAlign="center"
							align="left" allowSort="true">
							身份证号<input id="filter1" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="UserName" width="80px" headerAlign="center"
							align="left" allowSort="true">
							姓名<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="Amount" width="200px" headerAlign="center"
							align="right" allowSort="true" dataType="currency" summaryType="sum">返费总额(元)</div>
						<div field="UpdateTime" width="185px"
							dateFormat="yyyy-MM-dd HH:mm" headerAlign="center" align="center"
							allowSort="true">截止时间</div>
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="detailPan" class="subPageFrame" frameborder="0">
				</iframe>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var filterHelper = gridFilter();

		var typeBtn = mini.get("typeBtn");
		var datagrid1 = mini.get("datagrid1");
		var splitpan = mini.get("splitterPan");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		//双击
		function gridRowDbClick(e) {
			var id = e.row.Id;
			showDetail(id);
		}
		function showDetail(id) {
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/finance/detail/" />' + id);
		}
		function onselect() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			filterHelper.clearFilterData();
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("CardID",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("UserName",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var state = typeBtn.getValue();
			var url = "<c:url value='/finance/list/' />" + state;
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}

		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#separatorId2').show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#typeBtn').hide();
			$('#separatorId2').hide();
		}
		function status3Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#separatorId2').hide();
		}
		function reloadList() {
			datagrid1.reload();
		}

		function ondatagridDrawCell(e) {
			var field = e.field;
			var row = e.row;
			var grade = row.Grade;
			var cellCls = null;
			switch (grade) {
			case 1:
				cellCls = "deepDark";
				break;
			case 2:
				cellCls = "normalDark";
				break;
			default:
				cellCls = "lowDark";
				break;
			}
			e.cellCls = cellCls;
			if (field == "EmployState") {
				var value = e.value;
				var text = stateData[e.value].text;
				if (value == 1 || value == '1') {
					e.cellHtml = '<span style="color:red">' + text + '</span>';
				} else {
					e.cellHtml = text;
				}
			}
			if (field == "EmployLink") {
				var value = e.value;
				if (value) {
					if (!value.includes('http')) {
						value = "http://" + value;
					}
					e.cellHtml = '<a target="_blank" class="aTagUnderLine" href="'+value+'">'
							+ value + '</a>';
				}
			}
			if (field == "Action") {
				var id = row.Id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail('
						+ id + ')">[查看明细]</a>';
			}
		}
		function onDrawSummaryCell(e) {
			e.cellCls = "summaryStyle";
			var field = e.field;
			/* if (field == "Amount") {
				e.cellHtml = e.cellHtml.toFixed(2);
			} */
		}
		function checkBatch(){
			var rows = datagrid1.getSelecteds();
			if(rows.length < 1){
				mini.alert('请选择要返费的记录!');
				return;
			}
			mini.confirm("确定返费？", "确定？", function(action) {
				if (action == "ok") {
					var ids = null;
					for(var i=0,length=rows.length; i<length; i++){
						if(ids != null){
							ids += ",";
						}
						ids += rows[i].Id;
					}
					var url = rootPath + "/finance/remit";
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							"ids" : ids
						},
						success : function(data) {
							if (data) {
								top.commonTools.showTip("操作成功！", 1);
								datagrid1.reload();
							} else {
								top.commonTools.showTip("操作失败！", 2);
								datagrid1.reload();
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误！", 2);
						}
					});
				}
			});
		}
		function changeState(e){
			var value = e.value;
			if(value == 1){
				$('#checkBtn').show();
			}else{
				$('#checkBtn').hide();
			}
			onselect();
		}
	</script>
</body>
</html>